package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ContentRecords;
import com.ruoyi.system.service.IContentRecordsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 邮件内容Controller
 * 
 * @author xiaogu
 * @date 2024-10-23
 */
@RestController
@RequestMapping("/system/content")
public class ContentRecordsController extends BaseController
{
    @Autowired
    private IContentRecordsService contentRecordsService;

    /**
     * 查询邮件内容列表
     */
    @PreAuthorize("@ss.hasPermi('system:content:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContentRecords contentRecords)
    {
        startPage();
        List<ContentRecords> list = contentRecordsService.selectContentRecordsList(contentRecords);
        return getDataTable(list);
    }

    /**
     * 导出邮件内容列表
     */
    @PreAuthorize("@ss.hasPermi('system:content:export')")
    @Log(title = "邮件内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ContentRecords contentRecords)
    {
        List<ContentRecords> list = contentRecordsService.selectContentRecordsList(contentRecords);
        ExcelUtil<ContentRecords> util = new ExcelUtil<ContentRecords>(ContentRecords.class);
        util.exportExcel(response, list, "邮件内容数据");
    }

    /**
     * 获取邮件内容详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:content:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(contentRecordsService.selectContentRecordsById(id));
    }

    /**
     * 新增邮件内容
     */
    @PreAuthorize("@ss.hasPermi('system:content:add')")
    @Log(title = "邮件内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContentRecords contentRecords)
    {
        return toAjax(contentRecordsService.insertContentRecords(contentRecords));
    }

    /**
     * 修改邮件内容
     */
    @PreAuthorize("@ss.hasPermi('system:content:edit')")
    @Log(title = "邮件内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContentRecords contentRecords)
    {
        return toAjax(contentRecordsService.updateContentRecords(contentRecords));
    }

    /**
     * 删除邮件内容
     */
    @PreAuthorize("@ss.hasPermi('system:content:remove')")
    @Log(title = "邮件内容", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(contentRecordsService.deleteContentRecordsByIds(ids));
    }
}
